
#This file will be used to test the wilicoxon-mann-whiteny test#


from scipy import stats
import MySQLdb

#"""
database = "isec2014"
user = "root"
password="123"
port=3306

"""
database = "sangeeta"
user = "sangeetal"
password="sangeetal"
port=3307
#"""

db1= MySQLdb.connect(host="localhost", user=user, passwd=password,db=database, port=port)
select_cursor = db1.cursor() 

site = ['dba.stackexchange', 'programmers.stackexchange', 'superuser', 'serverfault', 'stackoverflow']
#post_fields = ['comment', 'score', 'view_count', 'comment_count', 'reputataion']

for current_table in site:
    
    table1 = 'stat_wo_migrated_to_q_'+current_table
    table2 = 'qimp_vote_rep'
    
    
    score1=[]
    score2=[]
    view_count1=[]
    view_count2=[]
    comment_count1=[]
    comment_count2=[]
    answer_count1=[]
    answer_count2=[]
    reputation1=[]
    reputation2= []
    
    query1 ="select  score, view_count, comment_count,answer_count, reputation from `"+table1+"`"
    select_cursor.execute(query1)
    data1 = select_cursor.fetchall()
    
    for temp_data1 in data1:
        score1.append(temp_data1[0])
        view_count1.append(temp_data1[1])
        comment_count1.append(temp_data1[2]) 
        answer_count1.append(temp_data1[3])
        reputation1.append(temp_data1[4])
    
    query2 = "select score, view_count, comment_count, answer_count, reputation from "+table2 +\
    " where migrated='"+current_table+"'"
    select_cursor.execute(query2)
   
    
    data2 = select_cursor.fetchall()
 
    for temp_data2 in data2:
        score2.append(temp_data2[0])
        view_count2.append(temp_data2[1])
        comment_count2.append(temp_data2[2]) 
        answer_count2.append(temp_data2[3])
        reputation2.append(temp_data2[4])
    
    print "table1=", table1
    #print "size data1=", len(data1), " data2=", len(data2)
    z_stat, p_val_score = stats.ranksums(score1, score2)
    z_stat, p_val_view = stats.ranksums(view_count1, view_count2)
    z_stat, p_val_comment = stats.ranksums(comment_count1, comment_count2)
    z_stat, p_val_answer = stats.ranksums(answer_count1, answer_count2)
    z_stat, p_val_reputation = stats.ranksums(reputation1, reputation2) 
    
    print "pvalue=> score=", p_val_score, " view=", p_val_view, " comment=", p_val_comment
    print " answer=", p_val_answer, " reputation=", p_val_reputation
    #print "comment2", comment_count2


#data1 = [1,2,3,4,5,6,7,8,9,10]
#data2 =[11,12,13,14,15,16,17,18,23,45,67,87,98]
 
  
  
#z_stat, p_val = stats.ranksums(data1, data2)
#
#print "pval", p_val
